using System;
using System.Drawing;
using System.Windows.Forms;
using ICSharpCode.TextEditor.Utils;

namespace ICSharpCode.TextEditor.UserControls
{
	public class ContextMenuStripEx : ContextMenuStrip
	{
		public ToolStripMenuItem AddToolStripMenuItem(string text, Bitmap bitmap, EventHandler<EventArgs> clickEvent, Keys keys, Func<bool> enabled)
		{
			ToolStripMenuItem menuItem = new ToolStripMenuItem(text);
			if (bitmap != null)
			{
				menuItem.Image = bitmap;
			}
			if (keys != 0)
			{
				menuItem.ShortcutKeys = keys;
			}
			if (clickEvent != null)
			{
				menuItem.Click += new WeakEventHandler<EventArgs>(clickEvent).Handler;
			}
			this.Items.Add(menuItem);
			EventHandler<EventArgs> callback = delegate
			{
				menuItem.Enabled = enabled();
			};
			base.Opening += new WeakEventHandler<EventArgs>(callback).Handler;
			return menuItem;
		}

		public ToolStripSeparator AddToolStripSeparator()
		{
			ToolStripSeparator toolStripSeparator = new ToolStripSeparator();
			this.Items.Add(toolStripSeparator);
			return toolStripSeparator;
		}

		protected override void Dispose(bool disposing)
		{
			base.Dispose(disposing);
		}
	}
}
